package cn.com.pet.community.action.userLogin;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import cn.com.pet.common.base.BaseAction;
import cn.com.pet.common.base.ErrorMessage;
import cn.com.pet.common.entity.User;
import cn.com.pet.common.service.UserService;
@Namespace("/action")
@ParentPackage("base")
@SuppressWarnings("serial")
public class UserLogin extends BaseAction{
	@Autowired
	UserService userService;
	
	@Action(value = "userLogin", results = {
			@Result(name = SUCCESS, location = "/html/community/home/petHome.jsp"),
			@Result(name = ERROR , location = "/html/community/Login/userLogin.jsp") })
	public String userLogin(){
		String userName = this.request.getParameter("userName");
		String passWord = this.request.getParameter("userPass");
		User u = new User();
		u.setUserNicky(userName);
		User user = userService.getUserByUserName(u);
		if(null != user && user.getPassWord().equals(passWord)){
			this.getRequest().setAttribute("user", user);
			return SUCCESS;
		}else{
			this.getRequest().setAttribute("error", ErrorMessage.USER_LOGIN_ERROR);
			return ERROR;
		}
	}
}
